
import * as Cesium from "cesium";
/* 空间两点距离计算函数 */
  const getSpaceDistance = (positions: any) => {
    let lengthAll = 0;
    for (let i = 0; i < positions.length - 1; i++) {
    // 1.将起点与终点位置信息从笛卡尔坐标形式转换为Cartographic形式
      const point1cartographic = Cesium.Cartographic.fromCartesian(positions[i]);
      const point2cartographic = Cesium.Cartographic.fromCartesian(positions[i + 1]);
    // 2.设置测地线起点和终点，EllipsoidGeodesic中setEndPoints常与surfaceDistance搭配使用
      const geodesic = new Cesium.EllipsoidGeodesic();
      geodesic.setEndPoints(point1cartographic, point2cartographic);
      // 3. 得到空间中点投影到地球表面的曲面距离
      let s = geodesic.surfaceDistance; // surfaceDistance返回number 单位为m，带小数
      // 4. 考虑两点的高度 利用直角三角形求斜边来求实际距离
      s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
      // 5.每段距离求和
      lengthAll += s
    }
    return lengthAll
  }
